#include "CSatelliteDeliveryDescriptor.h"


CSatelliteDeliveryDescriptor::CSatelliteDeliveryDescriptor(void):IDescriptorData(DESCRIPTOR_TAG_SATELLITE_DELIVERY)
, m_eCastResolutionType(1)
{	
}

CSatelliteDeliveryDescriptor::~CSatelliteDeliveryDescriptor(void)
{
}

void CSatelliteDeliveryDescriptor::GetData(BYTE* buff  , int &len)
{	 
/*
	unsigned char des[13]={0};
	FillIntToBCD((DWORD)(m_fFrequency * 100000), &des[2], 8);
	FillIntToBCD((DWORD)(m_fOrbitalPosition * 10), &des[6], 4);
	des[8]	= m_bWestEastFlag << 7 |m_byPolarization << 5 | m_byModulation;
	FillIntToBCD((DWORD)(m_fSymbolRate * 100000), &des[9], 7);
	des[12]	= (des[12] & 0xF0) | (m_byFECInner & 0x0F);
	
	CBuffer stBuffer(buff,DESCRIPTOR_MAXLEN);
	PACK_DESCRIPTOR_BUFFER_START(stBuffer,DESCRIPTOR_TAG_SATELLITE_DELIVERY);
	stBuffer.Write(des[2]);
	stBuffer.Write(des[3]);
	stBuffer.Write(des[4]);
	stBuffer.Write(des[5]);
	stBuffer.Write(des[6]);
	stBuffer.Write(des[7]);
	stBuffer.Write(des[8]);
	stBuffer.Write(des[9]);
	stBuffer.Write(des[10]);
	stBuffer.Write(des[11]); 
	stBuffer.Write(des[12]); 
	len = PACK_DESCRIPTOR_BUFFER_END(stBuffer);   //11 */


 
	std::string		csFrequency;
	std::string		csOrbitalPosition;
	std::string		csSymbolRate;
	std::string		csModulation;
	std::string		csPolarization;
	std::string		csFECInner;
	std::string		csWestEastFlag;

	csFrequency = ConvertToString((int)(m_fFrequency*100000/10*10)) ;
	csOrbitalPosition = ConvertToString(m_fOrbitalPosition) ;
	csSymbolRate = ConvertToString(m_fSymbolRate*10) ;
	csModulation = ConvertToString(m_byModulation) ;
	csPolarization = ConvertToString(m_byPolarization) ;
	csFECInner = ConvertToStringHex(m_byFECInner) ;
	csWestEastFlag = ConvertToString(m_bWestEastFlag) ; 

 
	std::string strDescriptor = "430B";//cable tag = 0x43; length = 0x0B;example: 430B 01175700 0192 21 0274500 0
    std::string strTemp;
	strTemp = csFrequency;
	for (unsigned int i=0; i<(8-strTemp.length()); i++)
	{
		strDescriptor += "0";
	}
	strDescriptor += strTemp;

	strTemp = csOrbitalPosition;
	for (unsigned int i = 0; i< (4 - strTemp.length()); i++)
	{
		strDescriptor += "0";
	}
	strDescriptor += strTemp;

	strTemp = ConvertToStringHex((m_bWestEastFlag<<7) || (m_byPolarization<<6) || m_byModulation) ;
	for (unsigned int i=0; i<(2-strTemp.length()); i++)
	{
		strDescriptor += "0";
	}
	strDescriptor += strTemp;

	strTemp= csSymbolRate;
	for (unsigned int i=0; i<(7-strTemp.length()); i++)
	{
		strDescriptor += "0";
	}
	strDescriptor += strTemp;

	strTemp = csFECInner;
	strDescriptor += strTemp;
	unsigned char cslen= 0;
	STR_HEX((char *)strDescriptor.c_str(),strDescriptor.length(),buff,(unsigned char*)&cslen) ;
	len = cslen;
}